/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.registration;

import java.io.Serializable;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.appfuse.webapp.util.FacesUtils;

/**
 * @date   May 10, 2012
 * @author ggutierrez
 */
public class ManagedBean implements Serializable {
    private transient RegistrationManager manager;    

    /** Creates a new instance of WebBean */
    public ManagedBean() {
    }

    public RegistrationManager getManager() {
        if (manager == null) {
            manager = (RegistrationManager) lookup("registrationManager");
        }
        return manager;
    }        
    
    public static Map<String, String> getParameterMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    }

    public static Map<String, String[]> getParameterValuesMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap();
    }

    public static Map<String, Object> getRequestMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
    }

    public static Map<String, Object> getSessionMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
    }

    public static Map<String, Object> getApplicationMap() {
        return FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
    }

    public static void addErrorMessage(String message) {
        FacesUtils.addErrorMessage(message);
    }

    public static void addInfoMessage(String message) {
        FacesUtils.addInfoMessage(message);
    }

    public static Object lookup(String name) {
        return FacesUtils.getManagedBean(name);
    }

    public void reset(String name) {
        ((ManagedBean) lookup(name)).reset();
    }

    public void dispose() {
    }

    public String startup() {
        return "fail";
    }

    public String startup(ActionEvent e) {
        return startup();
    }

    public String cancel() {
        return "cancel";
    }

    public void reset() {
    }
}
